#pragma once

#include <SDL.h>
#include "SceneBase.h"
#include "object.h"


class Game
{
public:

    static Game& getInstance()
    {
        static Game instance;
        return instance;
    };

    ~Game();

    /**
     * 初始化游戏
     */
    void init();

    /**
     * 运行游戏循环
     */
    void run();

    /**
     * 清理游戏资源
     */
    void clean();

    /**
     * 切换场景
     */
    void changeScene(SceneBase* scene);

    /**
     * 处理事件
     */
    void handleEvent(SDL_Event* event);

    /**
     * 更新游戏状态
     */
    void update(float deltaTime);

    /**
     * 渲染游戏画面
     */
    void render();

    /**
     * 更新背景
     */
    void updateBackground(float deltaTime);

    /**
     * 渲染背景
     */
    void renderBackground();


    SDL_Window* getWindow() { return window; }
    SDL_Renderer* getRenderer() { return renderer; }
    int getWindowWidth() { return windowWidth; }
    int getWindowHeight() { return windowHeight; }

private:
    Game();
    Game(const Game& other) = delete;
    Game& operator=(const Game& other) = delete;

    bool isRunning = true;
    SceneBase* currentScene = nullptr;
    SDL_Window* window = nullptr;
    SDL_Renderer* renderer = nullptr;
    int windowWidth = 600;
    int windowHeight = 800;

    // 帧率
    int FPS;
    // 锁定每帧耗费的时间
    uint32_t frameTime; 
    // 帧耗费时间
    float deltaTime;

    Background nearStar;
    Background farStar;
};